package com.ruoyi.coupon.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.coupon.domain.DistributionCoupon;
import com.ruoyi.coupon.service.IDistributionCouponService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分销优惠Controller
 * 
 * @author ruoyi
 * @date 2025-11-04
 */
@RestController
@RequestMapping("/ruoyi/coupon")
public class DistributionCouponController extends BaseController
{
    @Autowired
    private IDistributionCouponService distributionCouponService;

    /**
     * 查询分销优惠列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:coupon:list')")
    @GetMapping("/list")
    public TableDataInfo list(DistributionCoupon distributionCoupon)
    {
        startPage();
        List<DistributionCoupon> list = distributionCouponService.selectDistributionCouponList(distributionCoupon);
        return getDataTable(list);
    }

    /**
     * 导出分销优惠列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:coupon:export')")
    @Log(title = "分销优惠", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DistributionCoupon distributionCoupon)
    {
        List<DistributionCoupon> list = distributionCouponService.selectDistributionCouponList(distributionCoupon);
        ExcelUtil<DistributionCoupon> util = new ExcelUtil<DistributionCoupon>(DistributionCoupon.class);
        util.exportExcel(response, list, "分销优惠数据");
    }

    /**
     * 获取分销优惠详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:coupon:query')")
    @GetMapping(value = "/{couponId}")
    public AjaxResult getInfo(@PathVariable("couponId") Long couponId)
    {
        return success(distributionCouponService.selectDistributionCouponByCouponId(couponId));
    }

    /**
     * 新增分销优惠
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:coupon:add')")
    @Log(title = "分销优惠", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DistributionCoupon distributionCoupon)
    {
        return toAjax(distributionCouponService.insertDistributionCoupon(distributionCoupon));
    }

    /**
     * 修改分销优惠
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:coupon:edit')")
    @Log(title = "分销优惠", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DistributionCoupon distributionCoupon)
    {
        return toAjax(distributionCouponService.updateDistributionCoupon(distributionCoupon));
    }

    /**
     * 删除分销优惠
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:coupon:remove')")
    @Log(title = "分销优惠", businessType = BusinessType.DELETE)
	@DeleteMapping("/{couponIds}")
    public AjaxResult remove(@PathVariable Long[] couponIds)
    {
        return toAjax(distributionCouponService.deleteDistributionCouponByCouponIds(couponIds));
    }
}
